package cn.regexp.demo.ui;

import cn.hutool.core.date.DatePattern;
import cn.hutool.core.date.DateUtil;
import cn.regexp.demo.entity.Discussion;
import cn.regexp.demo.entity.Problem;
import com.intellij.util.ui.JBUI;
import lombok.Getter;
import lombok.Setter;

import javax.swing.*;
import java.awt.*;
import java.util.List;

/**
 * @author Regexpei
 * @date 2024/6/12 22:36
 * @description
 */
@Setter
@Getter
public class ProblemPanel {
    private JButton replyBtn;
    private JButton finishBtn;
    private JLabel title;
    private JLabel detail;
    private JLabel createTime;
    private JPanel discussionPanel;
    private JPanel mainPanel;


    public ProblemPanel(Problem problem) {
        this.title.setText(problem.getTitle());
        this.detail.setText(problem.getDetail());
        this.createTime.setText(DateUtil.format(problem.getCreateTime(), DatePattern.NORM_DATETIME_PATTERN));
        discussionPanel.setLayout(new GridBagLayout());

        List<Discussion> discussionList = problem.getDiscussionList();
        for (int i = 0; i < discussionList.size(); i++) {
            DiscussionPanel discussionPanel1 = new DiscussionPanel(discussionList.get(i));

            GridBagConstraints constraints = new GridBagConstraints(0, i, 1, 1, 1.0,
                    0, GridBagConstraints.NORTH, GridBagConstraints.BOTH, JBUI.insets(2), 0, 4);
            discussionPanel.add(discussionPanel1.getMainPanel(), constraints);
        }
    }

}
